using System;
using UnityEngine;

namespace Voodoo.Sauce.Internal
{
	public class VoodooLogger : ILogger
	{
		public int ModuleFilter { get; set; }

		public LogType LogLevel { get; set; }

		public event Action<string, string, LogType> logReceived;

		public VoodooLogger()
		{
			Application.logMessageReceived += ApplicationLogReceived;
			LogLevel = LogType.Log;
			ModuleFilter = 255;
		}

		private void ApplicationLogReceived(string message, string stackTrace, LogType type)
		{
			this.logReceived?.Invoke(message, stackTrace, type);
		}

		public void Log(string message, Module module, LogType logType)
		{
			if (LogLevel >= logType && (module == Module.NONE || ((uint)ModuleFilter & (uint)module) != 0))
			{
				switch (logType)
				{
				case LogType.Log:
					Debug.Log(message);
					break;
				case LogType.Warning:
					Debug.LogWarning(message);
					break;
				case LogType.Error:
					Debug.LogError(message);
					break;
				case LogType.Assert:
					break;
				}
			}
		}
	}
}
